using System;
using Xunit;

namespace LanguageLearnTestCase.Enum
{
    /// <summary>
    /// 多值并行位运算
    /// </summary>
    public class MultiValueParallelBitOperation
    {
        [Flags]
        public enum Type
        {
            ALL = 1 << 0, // 1
            B1 = 1 << 1, // 2
            B11 = 1 << 2, // 4
            B2 = 1 << 3, // 8
            B21 = 1 << 4, // 16
            A = 1 << 5, // 32
            Customer = 1 << 6, // 64
        }

        [Theory]
        [InlineData(1, Type.ALL)]
        [InlineData(24, Type.B2 | Type.B21)]
        [InlineData(35, Type.A | Type.ALL | Type.B1)]
        public void EqualInt32Value(int result, Type input)
        {
            Assert.Equal(result, (int)input);
        }


        [Theory]
        [InlineData(Type.A | Type.ALL | Type.B1, Type.A, true)]
        [InlineData(Type.A | Type.ALL | Type.B1, Type.ALL, true)]
        [InlineData(Type.A | Type.ALL | Type.B1, Type.B1, true)]
        [InlineData(Type.A | Type.ALL | Type.B1, Type.B2, false)]
        [InlineData(Type.A | Type.ALL | Type.B1, Type.Customer | Type.A, false)]
        public void IsContain(Type input, Type item, bool result)
        {
            Assert.Equal(result, (input & item) == item);
        }
        // private bool IsContainCheck<T>(T enum_combined_value, T enum_alone_value) where T : Enum
        // {
        //     return (enum_combined_value & enum_alone_value) == enum_alone_value;
        // }
    }
}
